export type CallBackFun<K,V> = (key:K,val:V)=> void

export class Dictionary<K,V>{
    private keys: K[] = []
    private vals: V[] = []

    constructor(key:K,val:V){
        const indexKey = this.keys.indexOf(key);
        if(indexKey >= 0){
            this.keys[indexKey] = key;
            this.vals[indexKey] = val;

        }else{
            this.keys.push(key);
            this.vals.push(val);
        }
    }
    //此处可以理解为，该函数需要传入一个回调函数，记住这个回调函数需要什么
    // 需要获得键值对，key和val。因此只要将key和val传给回调函数即可
    forEach(callBackFun:CallBackFun<K,V>){
        this.keys.forEach((k,i)=>{
            const v = this.vals[i];
            callBackFun(k,v)
        })
    }

} 